﻿package org.hsl.avm2.translation.mouse;
import flash.events.MouseEvent;
import org.hsl.haxe.translation.ITranslator;
import org.hsl.haxe.translation.NativeEvent;
/**
 * A translator that translates mouse events to deltas. Deltas indicate how many lines should be scrolled for each unit the
 * user rotates the mouse wheel. A positive delta value indicates an upward scroll; a negative value indicates a downward
 * scroll. Typical values are 3, -3, 1 and -1. However, the value depends on the device and operating system that the user is
 * using. Therefore, whether the value is positive or negative is more interesting than the actual value.
 */
// Ideally, the following line would be:
// class DeltaTranslator implements ITranslator<Int> {
// However, that doesn't work targetingAVM2.
class DeltaTranslator<D> implements ITranslator<D> {
	/**
	 * Creates a new delta translator.
	 */
	public function new():Void {
	}
	public function translate(nativeEvent:NativeEvent):D {
		var mouseEvent:MouseEvent;
		try {
			mouseEvent = cast(nativeEvent, MouseEvent);
		} catch (error:Dynamic) {
			throw "The nativeEvent argument must be a MouseEvent.";
		}
		return untyped mouseEvent.delta;
	}
}